<?php

    include('functions.php');
    
    if(!isset($_GET['i'])) exit('发生错误, 请返回!');
        else $idx = $_GET['i'];
    $type = isset($_GET['c'])?$_GET['c']:'';
    switch($type) {
        case 'u':
            $type = 'u';
            $title = 'UGC留言板';
            break;
        case 'r':
            $type = 'r';
            $title = '战队招募留言板';
            break;
        case 'n':
            $type = 'n';
            $title = '公告';
            break;    
        default:
            $type = 'd';
            $title = 'DJ留言板';
            break;       
    }

    $json = curl("http://www.djmaxcn.com/community/GetArticle.asp?i={$idx}&c={$type}");
    
    $rank = json_decode($json);
    
//    print_r($rank);
//    exit();
    
    if($rank->DATA->ROW === 0) exit('发生错误, 请返回!');
    
    getHead($rank->DATA->CONTENTS->TITLE, false);
    
    if($type != 'n') {
        
        $commentCount = count($rank->DATA->RECORD);
        $content = str_replace('&quot;', '"', $rank->DATA->CONTENTS->ARTICLE);
        
        echo <<<CONTENT
<p><strong>{$rank->DATA->CONTENTS->TITLE}</strong></p>
<p style="color: #666;">作者:<span style="color: #3586D5;">{$rank->DATA->CONTENTS->DJNAME}</span> 
(<span style="color: #3586D5;">{$rank->DATA->CONTENTS->DJLEVELNUMBER}</span>级|<span style="color: #3586D5;">{$rank->DATA->CONTENTS->CREWNAME}</span><span style="color: #9e9e9e;">{$rank->DATA->CONTENTS->CREWMEMBERLEVEL}</span>) <br />
日期: <span style="color: #3586D5;">{$rank->DATA->CONTENTS->REGDATE}</span>&#160;&#160;回复/查看: <span style="color: #3586D5;">{$commentCount}</span>/<span style="color: #3586D5;">{$rank->DATA->CONTENTS->HITCOUNT}</span></p>
{$content}
<p style="color: #888;">签名: {$rank->DATA->CONTENTS->DJCOMMENT}</p>
<hr/>
CONTENT;
        
        $i = 1;      
                                   
        if(!count($rank->DATA->RECORD)) echo '<p>无回复</p>';
        else {
            foreach($rank->DATA->RECORD as $recode) {
                $i++;
                $color = $rank->DATA->CONTENTS->DJNAME == $recode->DJNAME?'#3586D5':'green';
                $comment = preg_replace('/@.+ /U', '<span style="color:purple;">$0</span>', $recode->COMMENT);
                echo "<p><span style=\"color: #999;\">#{$i}</span>&#160;&#160;<span style=\"color: {$color}\">{$recode->DJNAME}</span><span style=\"color: gray\">的回复:</span><br />{$comment}</p>";
            }            
        }
        if(isset($_COOKIE['loginInfo']))
            echo <<<FORM
<form method="post" action="comment.php">
    <input type="hidden" name="c" value="{$type}"/>
    <input type="hidden" name="i" value="{$idx}"/>
    <textarea name="s" style="width: 100%; height: 60px;"></textarea>
    <input type="submit" value="留言"/>
</form>
FORM;
    } else {
        echo <<<CONTENT
<p><strong>{$rank->DATA->CONTENTS->TITLE}</strong></p>
<p style="color: #666;">作者:<span style="color: #3586D5;">白金会员</span> 
日期: <span style="color: #3586D5;">{$rank->DATA->CONTENTS->REGDATE}</span> &#160;&#160;&#160; 查看数: <span style="color: #3586D5;">{$rank->DATA->CONTENTS->HITCOUNT}</span></p>
{$rank->DATA->CONTENTS->ARTICLE}
CONTENT;
    }

    getFoot();
